package com.supermarket.model;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Timestamp;

/**
 * 临期商品申报实体类
 */
public class ExpiringProduct {
    private int id;
    private int productId;
    private int reportedBy;
    private BigDecimal currentStock;
    private Date expiryDate;
    private String suggestedAction; // DISCOUNT, DESTROY, RETURN
    private BigDecimal discountRate;
    private String status; // PENDING, APPROVED, REJECTED, PROCESSED
    private Integer approvedBy;
    private Date reportDate;
    private Date processedDate;
    private String remarks;
    private Timestamp createdAt;
    private Timestamp updatedAt;

    // 关联信息
    private String productCode;
    private String productName;
    private String unit;
    private BigDecimal salePrice;
    private String reporterName;
    private String approverName;

    // 构造函数
    public ExpiringProduct() {}

    // Getter和Setter方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getProductId() {
        return productId;
    }

    public void setProductId(int productId) {
        this.productId = productId;
    }

    public int getReportedBy() {
        return reportedBy;
    }

    public void setReportedBy(int reportedBy) {
        this.reportedBy = reportedBy;
    }

    public BigDecimal getCurrentStock() {
        return currentStock;
    }

    public void setCurrentStock(BigDecimal currentStock) {
        this.currentStock = currentStock;
    }

    public Date getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(Date expiryDate) {
        this.expiryDate = expiryDate;
    }

    public String getSuggestedAction() {
        return suggestedAction;
    }

    public void setSuggestedAction(String suggestedAction) {
        this.suggestedAction = suggestedAction;
    }

    public BigDecimal getDiscountRate() {
        return discountRate;
    }

    public void setDiscountRate(BigDecimal discountRate) {
        this.discountRate = discountRate;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Integer getApprovedBy() {
        return approvedBy;
    }

    public void setApprovedBy(Integer approvedBy) {
        this.approvedBy = approvedBy;
    }

    public Date getReportDate() {
        return reportDate;
    }

    public void setReportDate(Date reportDate) {
        this.reportDate = reportDate;
    }

    public Date getProcessedDate() {
        return processedDate;
    }

    public void setProcessedDate(Date processedDate) {
        this.processedDate = processedDate;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public Timestamp getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Timestamp createdAt) {
        this.createdAt = createdAt;
    }

    public Timestamp getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Timestamp updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getProductCode() {
        return productCode;
    }

    public void setProductCode(String productCode) {
        this.productCode = productCode;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public BigDecimal getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(BigDecimal salePrice) {
        this.salePrice = salePrice;
    }

    public String getReporterName() {
        return reporterName;
    }

    public void setReporterName(String reporterName) {
        this.reporterName = reporterName;
    }

    public String getApproverName() {
        return approverName;
    }

    public void setApproverName(String approverName) {
        this.approverName = approverName;
    }

    /**
     * 获取状态显示文本
     */
    public String getStatusText() {
        switch (status) {
            case "PENDING":
                return "待审批";
            case "APPROVED":
                return "已批准";
            case "REJECTED":
                return "已拒绝";
            case "PROCESSED":
                return "已处理";
            default:
                return status;
        }
    }

    /**
     * 获取建议处理方式显示文本
     */
    public String getSuggestedActionText() {
        switch (suggestedAction) {
            case "DISCOUNT":
                return "打折销售";
            case "DESTROY":
                return "销毁处理";
            case "RETURN":
                return "退回供应商";
            default:
                return suggestedAction;
        }
    }

    /**
     * 获取建议处理方式描述
     */
    public String getSuggestedActionDescription() {
        return getSuggestedActionText();
    }

    /**
     * 获取状态描述
     */
    public String getStatusDescription() {
        return getStatusText();
    }

    /**
     * 验证数据
     */
    public String validateData() {
        if (productId <= 0) {
            return "商品ID无效";
        }
        if (reportedBy <= 0) {
            return "申报人ID无效";
        }
        if (currentStock == null || currentStock.compareTo(BigDecimal.ZERO) < 0) {
            return "当前库存无效";
        }
        if (expiryDate == null) {
            return "到期日期不能为空";
        }
        if (suggestedAction == null || suggestedAction.trim().isEmpty()) {
            return "建议处理方式不能为空";
        }
        if ("DISCOUNT".equals(suggestedAction) && 
            (discountRate == null || discountRate.compareTo(BigDecimal.ZERO) <= 0 || 
             discountRate.compareTo(new BigDecimal("100")) > 0)) {
            return "折扣率必须在0-100之间";
        }
        return null; // 验证通过
    }
}